//
// Created by ChenJi on 2020/12/5.
//
#include "usart_extern.h"
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
extern UART_HandleTypeDef huart3;
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart5;
extern DMA_HandleTypeDef hdma_uart4_rx;
extern DMA_HandleTypeDef hdma_uart4_tx;
extern DMA_HandleTypeDef hdma_usart1_rx;
extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart2_rx;
extern DMA_HandleTypeDef hdma_usart2_tx;
extern DMA_HandleTypeDef hdma_usart3_rx;
extern DMA_HandleTypeDef hdma_usart3_tx;

uint8_t uart1_buffer[1];
uint8_t uart2_buffer[1];
uint8_t uart3_buffer[1];
uint8_t uart4_buffer[13];

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
    if(huart==&huart1){
        onUART1Receive(uart1_buffer[0]);
    }
    if(huart==&huart2){
        onUART2Receive(uart2_buffer[0]);
    }
    if(huart==&huart3){
        onUART3Receive(uart3_buffer[0]);
    }
    if(huart==&huart4){
        onUART4Receive(uart4_buffer[0]);
    }
}
void EX_DMA_Receive_Init(){
    HAL_UART_Receive_DMA(&huart1,uart1_buffer,1);
    HAL_UART_Receive_DMA(&huart2,uart2_buffer,1);
    HAL_UART_Receive_DMA(&huart3,uart3_buffer,1);
    HAL_UART_Receive_DMA(&huart4,uart4_buffer,1);
}

HAL_StatusTypeDef sendData(uint8_t *data,UART_HandleTypeDef *uart,uint16_t len){
    return HAL_UART_Transmit(uart,data,len,100);
}

HAL_StatusTypeDef sendData_DMA(uint8_t *data,UART_HandleTypeDef *uart,uint16_t len){
    return HAL_UART_Transmit_DMA(uart,data,len);
}
HAL_StatusTypeDef debug_UART1(uint8_t *data,uint16_t len){
    sendData_DMA(data,&huart1,len);
    return 0;
}


